package hotLeetcode;

public class H234Leetcode {
    //回文链表 解法1 翻转链表
    public boolean isPalindrome(ListNode head) {
        //翻转链表
        ListNode newListNode = reserve(head);

        while (head != null) {
            if (newListNode.val != head.val) return false;
            head = head.next;
            newListNode = newListNode.next;

        }


        return true;



    }

    private ListNode reserve(ListNode head) {
        ListNode newListNode = null;
        while (head != null) {
            newListNode = new ListNode(head.val, newListNode);
            head = head.next;
        }

        return newListNode;


    }

     public class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
}
